home *** CD-ROM | disk | FTP | other *** search
- /* swab.c, from p.161 of Turbo C Bible */
- /* Takes an array of bytes and swaps contents of each pair of adjacent bytes. */
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- main(int argc, char **argv)
- {
- size_t len;
- char src[80], dst[80];
- if (argc < 2) /* Make sure there are two argument */
- {
- printf("Usage: %s <srting ofr \"swab\">\n", argv[0]);
- abort();
- }
- len = 2*(strlen(argv[1])/2);/* Take an even number of characters */
- strncpy(src, argv[1], len); /* and feed it to swab */
- src[len] = '\0'; /* Mark the end of string in */
- dst[len] = '\0'; /* source and destination */
- swab(src, dst, len); /* Now copy after swapping */
- printf("Input string to \"swab\": %s\n "
- "Output string to \"swab\": %s\n", src, dst);
- /* adjacent bytes */
- }